package com.sdp.khy.baotou.controller;


import com.sdp.core.bizc.db.Query;
import com.sdp.core.bizc.vo.DataCenter;
import com.sdp.core.bizc.vo.Result;
import com.sdp.khy.baotou.cache.clean.KhyCleanCache;
import com.sdp.khy.baotou.db.khy_user.entity.KhyUser;
import com.sdp.khy.baotou.db.khy_user.service.IKhyUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zsp
 * @since 2023-11-29
 */
@RestController
@RequestMapping("/KhyUseController")
public class KhyUseController {

	@Autowired
	private IKhyUserService iKhyUserService;

	@Autowired
	private Query query;

	@Autowired
	private KhyCleanCache khyCleanCache;

	@PostMapping(value = "/page")
	public Result<?> page(@RequestBody DataCenter dataCenter) {
		return Result.ok(query.page(iKhyUserService, KhyUser.class, dataCenter));
	}

	@GetMapping(value = "/del")
	@Transactional(rollbackFor=Exception.class)
	public Result<?> del(@RequestParam(name="keyId",required=true) String keyId) {
		if(StringUtils.isEmpty(keyId)) {
			return Result.error("需要删除的记录信息不完整");
		}
		iKhyUserService.removeById(keyId);
		khyCleanCache.cleanBusCache();
		return Result.ok();
	}
}

